﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FlyCapture2Managed;

namespace DualChannel_v2._0
{
    public partial class CameraControlForm : Form
    {
        public CameraControlForm()
        {
            InitializeComponent();
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            BackColor = Color.Transparent;
            flowLayoutPanel1.BackColor = Color.Transparent;
            panel1.BackColor = Color.Transparent;
            this.BackColor = Color.Green;
            this.TransparencyKey = Color.Green;

            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            Hide();
        }

        SavebleCameraProperty[] cp = null;
        CameraPropertyInfo[] cpi=null;
        ManagedCameraBase Cam = null;
        public ManagedCameraBase Camera { get { return Cam; } } 

        public void Populate(ManagedCameraBase Cam)
        {
            this.Cam = Cam;
            cp = new SavebleCameraProperty[18];
            cpi = new CameraPropertyInfo[18];
            flowLayoutPanel1.Controls.Clear();
            for (int i = 0; i < 18; i++)
            {
                cp[i] = new SavebleCameraProperty((Cam as ManagedCameraBase).GetProperty((PropertyType)i));
                cpi[i] = Cam.GetPropertyInfo(cp[i].type);
                if (cp[i].present)
                {
                    CameraPropertyControl pc = new CameraPropertyControl(cp[i], cpi[i]);
                    flowLayoutPanel1.Controls.Add(pc);
                    pc.PropChanged += new DualChannel_v2._0.CameraPropertyControl.PropChangeEvent(this.SetCam);
                }
                
   
            }
            //flowLayoutPanel1.Controls.Add(button1);

            

        }

        public void SetCam(CameraPropertyControl cpc, CameraProperty cp)
        {
            Cam.SetProperty(cp);
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!flowLayoutPanel1.Visible || Cam==null)
                return;
            for (int i = 0, c=0; i < 18; i++)
            {
                cp[i] = new SavebleCameraProperty((Cam as ManagedCameraBase).GetProperty((PropertyType)i));
                cpi[i] = Cam.GetPropertyInfo(cp[i].type);
                if (cp[i].present)
                {

                    (flowLayoutPanel1.Controls[c++] as CameraPropertyControl).RefreshData(cp[i], cpi[i]);
                }
            }

        }
        private void CameraControlForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            timer1.Stop();
        }


    }
}
